//
//  LAB_Filters.m
//  Camera
//
//  Created by Bodi on 16/8/15.
//  Copyright © 2016年 葛海一. All rights reserved.
//

#import "LAB_Filters.h"
@interface LAB_Filters()
@property (nonatomic, strong, readwrite) UIImage         *   filterImg;
@end
@implementation LAB_Filters
- (instancetype)initWithImage:(UIImage *)image filterName:(NSString *)name{
    self = [super init];
    if (self) {
        //转换Image格式
        CIImage * ciImg = [[CIImage alloc] initWithImage:image];
        //创建
        CIFilter * filter = [CIFilter filterWithName:name keysAndValues:kCIInputImageKey,ciImg, nil];
        [filter setDefaults];
        //绘制内容
        CIContext * context = [CIContext contextWithOptions:nil];
        //渲染输出
        CIImage * outFilterImg = [filter outputImage];
        //CGImage句柄
        CGImageRef cgImg = [context createCGImage:outFilterImg fromRect:[outFilterImg extent]];
        _filterImg = [UIImage imageWithCGImage:cgImg];
        
        //释放CGImage句柄
        CGImageRelease(cgImg);
    }
    return self;

}
@end
